﻿using System;

namespace Graphix.Elements
{
    using System.Collections;
    using System.Drawing;
    using System.Drawing.Drawing2D;

    using Graphix.Helpers;

    using SvgNet.SvgGdi;

    public abstract class BaseElement : IElement
    {
        public Hashtable Attributes { get; set; }

        private PointF position;

        private float opacity;

        #region Implementation of IElement

        public BaseElement()
        {
            this.Attributes = new Hashtable();
        }

        public BaseElement(float x, float y, Brush color = null) : this()
        {
            this.Position = new PointF(x, y);
            this.Color = color ?? Brushes.Black;
            this.Opacity = 1f;
        }

        public abstract void Draw(IGraphics graphics);

        public void Move(float x, float y)
        {
            this.position.X += x;
            this.position.Y += y;
        }

        public float Opacity
        {
            get
            {
                return this.opacity;
            }
            set
            {
                if (value < 0)
                {
                    value = 0;
                }
                else if (value > 1)
                {
                    value = 1;
                }

                this.opacity = value;
            }
        }

        public Brush Color { get; set; }

        public PointF Position
        {
            get
            {
                return this.position;
            }
            set
            {
                this.position = value;
            }
        }

        public Horizontal Alignment { get; set; }

        public Vertical VerticalAlignment { get; set; }

        public Orientation Orientation { get; set; }

        public Matrix Transformation { get; set; }

        public PerformMove MoveWhen { get; set; }

        #endregion
    }
}
